package com.sharding.transaction.demo.provider;

import com.sharding.transaction.demo.api.IOrderProviderService;
import com.sharding.transaction.demo.api.IStoreProviderService;
import com.sharding.transaction.demo.entity.Goods;
import com.sharding.transaction.demo.entity.Orders;
import com.sharding.transaction.demo.service.GoodsService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;

@org.apache.dubbo.config.annotation.Service(protocol = "dubbo", version = "1.0.0", group = "sharding-tr" )
public class GoodsProviderServiceImpl implements IStoreProviderService {

    @Autowired
    private GoodsService service;

    @Override
    public Integer deductionStoreSuc(Integer store, Long goodsId) {
        Integer cont = service.deductionStore(goodsId, store);
        if(cont > 0) return cont;
        throw new RuntimeException("库存更新失败！！！");
    }

    @Override
    public Orders deductionStoreFail(Integer store, Long goodsId) {
        return null;
    }

    @Override
    public Goods getById(Long id) {
        return service.getById(id);
    }
}
